package xworker.gluon.attach;

import com.gluonhq.attach.statusbar.StatusBarService;
import javafx.scene.paint.Color;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.scene.paint.ColorActions;

public class StatusbarActions {
    public static void setColor(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        Color color = null;
        String key = self.getStringBlankAsNull("color");
        if(key != null){
            color = ColorActions.colors.get(key);
        }

        if(color == null){
            String web = self.getStringBlankAsNull("webColor");
            if(web != null){
                color = Color.web(web);
            }
        }

        if(color != null) {
            Color finalColor = color;
            StatusBarService.create().ifPresent(service -> service.setColor(finalColor));
        }
    }
}
